package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p=new Person("李四");
        System.out.println(p);
        Class cls=Class.forName("reflect.Person");
        Constructor c=cls.getConstructor(String.class);
        Object obj=c.newInstance("王五");
        System.out.println(obj);

        Constructor c2=cls.getConstructor(String.class,int.class);
        Object obj2=c2.newInstance("赵六",32);
        System.out.println(obj2);

//        Student s1=new Student("佳佳",7);
//        Student s2=new Student("美美",8);
        Constructor c3=cls.getConstructor(String.class,int.class);
        Class cls3=Class.forName("reflect.Student");
        Object obj3=c3.newInstance("佳佳",7);
        Object obj4=c3.newInstance("美美",8);
        System.out.println(obj3);
        System.out.println(obj4);

        Constructor c4=cls.getConstructor();
        Object obj5=c4.newInstance();
        System.out.println(obj5);
    }
}
